home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / filters.zip / TRUNC.ASM < prev    next >
Assembly Source File  |  1986-11-27  |  3KB  |  104 lines

  1.     Name trunc
  2.     Title
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that reads a file and truncates each
  7.     line at the character on the parmline or the eol char <CR>.
  8.     If there is not parameter lines will be truncated at the first
  9.     space (which includes leading spaces as well.)
  10.  
  11. /
  12. ;===================================================================
  13. code    segment    public
  14. ;===================================================================
  15. ;
  16. ;    command line is at 80h of psp - first byte is length
  17. ;
  18.     org    80h
  19. parmsize    db    ?
  20. parm        db    7fh dup (?)
  21. ;
  22. ; .com starts at 100h - but must jump around any data area
  23. ;
  24.     org    100h            ; com file starts here
  25.     assume    cs:code,ds:code,es:code
  26. trunc:
  27.     jmp    clear
  28. ;===================================================================
  29. ;
  30. ; data area for .com programs
  31. ; Uncomment (**) statements and comment (&&) statements
  32. ; if you need two different buffers.
  33. ;
  34. inchar      db    ?
  35. ;
  36. ;===================================================================
  37. clear:
  38. ;
  39. ; start of actual code is here (clear)
  40. ;
  41. ;
  42. ; Read a character.  If it compares to the current character of the
  43. ; parmline, loop through the end of the line (CR/LF).
  44. ;
  45. ; Check parameter line for a character.  If none, insert a space.
  46. ;
  47.     cmp    parmsize,2h    ; if no characters, insert a space.
  48.     jge    parmok
  49.     mov    parm+1,' '    ; tack on the space
  50.  
  51. ; These two i/o parameters are constants.
  52. ;
  53. parmok:
  54.     lea    dx,inchar    ; offset of inchar
  55.     mov    cx,1h        ; get 1 character
  56. again:
  57. ;
  58. ; read a character
  59. ;
  60.     xor    bx,bx        ; zero is handle of standard input
  61.     lea    dx,inchar    ; offset of inchar
  62.     mov    ah,3fh        ; read a file/device function
  63.     int    21h        ; invoke the function
  64. ;
  65. ; if carry set of ax=0 exit
  66. ;
  67.     jc    oops        ; i/o error
  68.     and    ax,ax        ; set flags
  69.     jz    oops        ; eof
  70. ;
  71. ; compare character against parmline.
  72. ;
  73.     mov    al,parm+1    ; load character
  74.     cmp    al,inchar
  75.     jne    output        ; if characters don't match, output
  76. ;
  77. ; Character matched - now read characters until <cr> is seen.
  78. ;
  79. skip:
  80.     xor    bx,bx        ; zero is handle of standard input
  81.     mov    cx,1h        ; get 1 character
  82.     mov    ah,3fh        ; read a file/device function
  83.     int    21h        ; invoke the function
  84. ;
  85. ; if carry set of ax=0 exit
  86. ;
  87.     jc    oops        ; i/o error
  88.     and    ax,ax        ; set flags
  89.     jz    oops        ; eof
  90. ;
  91. ; look for <cr>
  92. ;
  93.     cmp    inchar,0dh    ; if inchar is <cr>, start i/o again.
  94.     jne    skip        ; otherwise skip it.
  95. output:
  96.     mov    bx,1h        ; standard output handle
  97.     mov    ah,40h        ; dx still points at inchar
  98.     int    21h        ; call dos output function
  99.     jmp    again        ; repeat cycle
  100. oops:
  101.     int    20h        ; return to dos
  102. code    ends
  103.     end    trunc
  104.